package com.gccloud.design;

import com.gccloud.design.dto.SdApiParamDto;
import com.gccloud.design.service.SdApiParamScriptService;
import com.gccloud.starter.common.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author wu.yumin
 * @version 1.0.0
 * @Description
 * @date 2021/10/20 09:17
 */
@RestController
@RequestMapping("/api/param")
@Api(tags = "api模版参数脚本配置")
public class SdApiParamScriptController {

    @Resource
    private SdApiParamScriptService sdApiParamScriptService;

    @GetMapping("/relaParams/{apiId}")
    @ApiOperation(value = "查询api参数模版", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "apiId", value = "apiId", required = true, dataType = "String", paramType = "path")
    public R<SdApiParamDto> queryRelaParams(@PathVariable("apiId") String apiId) {
        SdApiParamDto dto = sdApiParamScriptService.queryConfig(apiId);
        return R.success(dto);
    }

    @PostMapping("/relaParams")
    @ApiOperation(value = "更新api模版参数额配置", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<Object> queryScriptTemplate(@RequestBody SdApiParamDto dto) {
        sdApiParamScriptService.saveOrUpdateConfig(dto);
        return R.success();
    }


}
